package com.taiyi.renaissancemall.ui.main.goodsdetail

import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.graphics.Paint
import android.net.Uri
import android.net.http.SslError
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import android.webkit.*
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
import com.taiyi.renaissancemall.R
import com.taiyi.renaissancemall.Utils.*
import com.taiyi.renaissancemall.adapter.AdapterManager
import com.taiyi.renaissancemall.base.BaseActivity
import com.taiyi.renaissancemall.base.MyApp
import com.taiyi.renaissancemall.bean.GoodDetailShareBean
import com.taiyi.renaissancemall.bean.GoodsDetailBean
import com.taiyi.renaissancemall.bean.ProductSpecPriceBean
import com.taiyi.renaissancemall.ui.main.brand.BrandListActivity
import com.taiyi.renaissancemall.ui.main.goodsdetail.commentList.CommentListActivity
import com.taiyi.renaissancemall.ui.main.order.ProductFillOrderActivity
import com.taiyi.renaissancemall.ui.main.personshare.personshare2.PersonShare2Activity
import com.taiyi.renaissancemall.ui.main.shoppingcar.ShoppingCarActivity
import com.taiyi.renaissancemall.ui.mine.order.ask_every_one.AskEveryoneListActivity
import com.taiyi.renaissancemall.wxapi.WXEntryActivity
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject
import com.zhouwei.mzbanner.MZBannerView.BannerPageClickListener
import com.zhouwei.mzbanner.holder.MZHolderCreator
import kotlinx.android.synthetic.main.activity_goods_detail.*
import kotlinx.android.synthetic.main.base_top_white_background_layout.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe

class GoodsDetailActivity : BaseActivity<GoodsDetailView, GoodsDetailPresent>(), GoodsDetailView {

    var tvList = mutableListOf<TextView>()
    override fun getLayoutId(): Int = R.layout.activity_goods_detail
    lateinit var specDailog: Dialog
    lateinit var specRecyclerView: RecyclerView
    lateinit var specIv: ImageView
    lateinit var specCloseIv: ImageView
    lateinit var specAddIv: ImageView
    lateinit var specNumEt: EditText
    lateinit var specJianIv: ImageView
    lateinit var specPrice: TextView
    lateinit var specBVPrice: TextView
    lateinit var specNowBuyTv: TextView
    lateinit var specAddShoppingCarTv: TextView
    lateinit var specInStockTv: TextView
    lateinit var goodsDetailBean: GoodsDetailBean
    lateinit var productSpecIds: String
    lateinit var commodityspecid: String

    var num = 1

    lateinit var shareDialog: Dialog
    lateinit var shareView: View

    override fun initPresenter(): GoodsDetailPresent = GoodsDetailPresent()


    override fun initViews(savedInstanceState: Bundle?) {
        titleTv.text = getString(R.string.goodsDetail)
        EventBus.getDefault().register(this)
        shareDialog = Dialog(this, R.style.MyDialog)
        shareView = LayoutInflater.from(this).inflate(R.layout.good_share_dialog_layout, null)
        shareDialog.setContentView(shareView)

        rightIv.setImageResource(R.mipmap.goods_detail_share_iv)
        specDailog = Dialog(this, R.style.MyDialog)
        goodsTv.isSelected = true
        tvList.add(labelOneTv)
        tvList.add(labelTwoTv)
        tvList.add(labelThreeTv)
        var inflate = View.inflate(this, R.layout.specification_dialog_layout, null)
        specDailog.setContentView(inflate)
        specRecyclerView = inflate.findViewById<RecyclerView>(R.id.specRecyclerView)
        specIv = inflate.findViewById<ImageView>(R.id.iv)
        specNumEt = inflate.findViewById<EditText>(R.id.numEt)
        specCloseIv = inflate.findViewById<ImageView>(R.id.specCloseIv)
        specAddIv = inflate.findViewById<ImageView>(R.id.addIv)
        specJianIv = inflate.findViewById<ImageView>(R.id.jianIv)
        specPrice = inflate.findViewById<TextView>(R.id.priceTv)
        specBVPrice = inflate.findViewById<TextView>(R.id.bvPriceTv)
        specNowBuyTv = inflate.findViewById<TextView>(R.id.nowBuyTv)
        specInStockTv = inflate.findViewById<TextView>(R.id.inStockTv)
        specAddShoppingCarTv = inflate.findViewById<TextView>(R.id.addShoppingCarTv)
        specAddShoppingCarTv.setOnClickListener {

            showProgress()
            presenter.addShoppingCar()
        }
        specAddIv.setOnClickListener {
            num += 1
            specNumEt.setText(num.toString())
        }
        specJianIv.setOnClickListener {
            if (num == 1) return@setOnClickListener
            num -= 1
            specNumEt.setText(num.toString())
        }
        specNowBuyTv.setOnClickListener {
            specDailog.dismiss()
            var bundle = Bundle()
            bundle.putString("commodityspecid", commodityspecid)
            bundle.putString("num", specNumEt.text.toString())
            ActivityUtils.next(this, ProductFillOrderActivity::class.java, bundle)
        }
        nowBuyTv.setOnClickListener {
            specDailog.show()
        }
        addShoppingCarTv.setOnClickListener {
            specDailog.show()
        }
        specCloseIv.setOnClickListener {
            specDailog.dismiss()
        }
        var attributes = specDailog.window?.attributes
        attributes?.run {
            gravity = Gravity.BOTTOM
            width = ViewGroup.LayoutParams.MATCH_PARENT
        }
        specDailog.window?.attributes = attributes
        productSpecificationsTv.setOnClickListener {
            specDailog.show()
        }
        goodsTv.setOnClickListener {
            goodsTv.isSelected = true
            detailsTv.isSelected = false
            commentTv.isSelected = false
            nestedScrollView.smoothScrollTo(0, 0)
        }
        detailsTv.setOnClickListener {
            goodsTv.isSelected = false
            detailsTv.isSelected = true
            commentTv.isSelected = false
            nestedScrollView.smoothScrollTo(0, myWebView.top)
        }
        commentTv.setOnClickListener {
            goodsTv.isSelected = false
            detailsTv.isSelected = false
            commentTv.isSelected = true
            nestedScrollView.smoothScrollTo(0, productReview.top)
        }

        shoppingCarIv.setOnClickListener {
            startActivity(Intent(this, ShoppingCarActivity::class.java))
        }

        brandTv.setOnClickListener {
            var brandId = goodsDetailBean?.product?.brandid.toString()
            var brandName = goodsDetailBean?.product?.brandname
            var intent = Intent(this, BrandListActivity::class.java)
            intent.putExtra("brandId", brandId)
            intent.putExtra("brandName", brandName)
            startActivity(intent)
        }

        pVideoIv.setOnClickListener {
            var intent = Intent(this, PlayVideoActivity::class.java)
            intent.putExtra("videoUrl", goodsDetailBean?.product?.videourl)
            startActivity(intent)
        }

        collectIv.setOnClickListener {
            if (isCollection == "1") {//已收藏
                //取消收藏
                showProgress()
                presenter.cancelCollection()
            } else {//未收藏
                //收藏
                showProgress()
                presenter.addCollection()
            }
        }
        viewSimilarProductsTv.setOnClickListener {
            var sanfurl = goodsDetailBean?.product?.sanfurl
//            var intent = Intent(this, WebViewActivity::class.java)
//            intent.putExtra("url", sanfurl)
//            intent.getIntExtra("isWhere", 4)
//            startActivity(intent)
            var intent = Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(sanfurl));
            // 注意此处的判断intent.resolveActivity()可以返回显示该Intent的Activity对应的组件名
            // 官方解释 : Name of the component implementing an activity that can display the intent
            if (intent.resolveActivity(getPackageManager()) != null) {
                var componentName = intent.resolveActivity(getPackageManager());
                // 打印Log   ComponentName到底是什么
                startActivity(Intent.createChooser(intent, "请选择浏览器"));
            } else {
                toast("未找到此链接")
            }
        }
        rightIv.setOnClickListener {
            WXEntryActivity.type = 2
            showProgress()
            presenter.getShareInfo()
        }
        askAQuestionTv.setOnClickListener {
            var intent = Intent(this, AskEveryoneListActivity::class.java)
            intent.putExtra("commodityid", goodsDetailBean?.product?.commodityid)
            startActivity(intent)
        }
        productReview1.setOnClickListener {
            var intent = Intent(this, CommentListActivity::class.java)
            intent.putExtra("commodityid", goodsDetailBean?.product?.commodityid)
            intent.putExtra("commodityscore", "")//评分
            startActivity(intent)
        }


        showProgress()
        presenter.getGoodsDetail()
    }


    override fun initImmersionBar() {
        super.initImmersionBar()
        mImmersionBar.titleBar(top).init();

    }

    override fun initData() {

    }

    override fun initEvent() {
        backIv.setOnClickListener {
            finish()
        }
    }

    @Subscribe
    fun getScore(s: String) {
        if (s.startsWith("shareProductSuccess")) {
            ToastUtils.showLongToast("分享成功")
            showProgress()
            presenter.shareGetScore()
        }
    }

    var isCollection = ""
    override fun getGoodsDetailSuccess(goodsDetailBeans: GoodsDetailBean?) {
        hideProgress()
        isCollection = goodsDetailBeans?.product?.ifcollection!!
        if (goodsDetailBeans?.product?.ifcollection == "1") {
            collectIv.setImageResource(R.mipmap.yes_collect_iv)
        } else {
            collectIv.setImageResource(R.mipmap.no_collect_iv)
        }
        goodsDetailBean = goodsDetailBeans!!


        commodityspecid = goodsDetailBeans.product?.commodityspecid!!
        var product = goodsDetailBean?.product

        if (product?.sanftype == "1") {//1淘宝2京东
            sanLogoIv.visibility = VISIBLE
            sanLogoIv.setImageResource(R.mipmap.product_detail_tb_logo)
        } else if (product?.sanftype == "2") {
            sanLogoIv.visibility = VISIBLE
            sanLogoIv.setImageResource(R.mipmap.product_detail_jd_logo)
        }
        pPriceTv.text = "普通价格：${product.price}元"
        pMemberPriceTv.text = "年卡会员价：${product.hyprice}元"
        ttv.text = "立省：${product.price.toDouble() - product.hyprice.toDouble()}元"

        specIv.load(product!!.smallimgurl)
        goodNameTv.text = product?.name.replace("\r\n", "", true)
        goodDescriptionTv.text = product?.combz
        oldPriceTv.text = "￥" + product?.sanfprice
        oldPriceTv.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG

        if (goodsDetailBeans.ifhui == "1") {
            bvPriceTv.text = product?.hybvprice + "BV"
            priceTv.text = "￥" + product?.hyprice
        } else {
            bvPriceTv.text = product?.bvprice + "BV"
            priceTv.text = "￥" + product?.price
        }
        brandTv.text = product?.brandname
        if (!product?.lableidname.isNullOrEmpty()) {
            if (product?.lableidname?.contains(",", true)!!) {
                var split = product?.lableidname.split(",")
                labelRecyclerView.run {
                    layoutManager = FlowLayoutManager(this@GoodsDetailActivity, true)
                    adapter = AdapterManager.getProductDetailLabelListAdapter(
                        this@GoodsDetailActivity,
                        split
                    );
                }
            } else {
                tvList[0].visibility = VISIBLE
                tvList[0].text = product?.lableidname
            }
        }
        var commentlist = goodsDetailBean?.commentlist
        var split = product?.comimgurl?.split(",")
        myWebView.settings.javaScriptEnabled = true
        myWebView.settings.setSupportZoom(false)
        myWebView.settings.builtInZoomControls = false
        myWebView.settings.displayZoomControls = false
        myWebView.settings.useWideViewPort = true
        myWebView.settings.domStorageEnabled = true
        myWebView.settings.useWideViewPort = true;
        myWebView.settings.loadWithOverviewMode = true
        myWebView.settings.blockNetworkImage = false
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            myWebView.settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW; }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
            myWebView.settings.layoutAlgorithm =
                WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING; //支持内容重新布局
        else
            myWebView.settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;

        myWebView.settings.loadsImagesAutomatically = true
        myWebView.webViewClient = (object : WebViewClient() {
            override fun onPageFinished(p0: WebView?, p1: String?) {
                super.onPageFinished(p0, p1)

                myWebView.measure(0, 0)
                var measuredHeight = myWebView.measuredHeight
                var layoutParams = myWebView.layoutParams
                layoutParams.height = measuredHeight
                myWebView.layoutParams = layoutParams
            }


            override fun shouldOverrideUrlLoading(
                p0: WebView?,
                request: WebResourceRequest?
            ): Boolean {
                //解决android7.0以后版本加载异常问题
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    p0?.loadUrl(request?.getUrl().toString());
                } else {
                    p0?.loadUrl(request?.toString());
                }
                return true
            }

            override fun onReceivedSslError(
                p0: WebView?,
                handler: SslErrorHandler?,
                error: SslError?
            ) {
                handler?.proceed()
            }

        })
        var htmlData = getHtmlData(product?.detailimgurl!!)
        myWebView.loadDataWithBaseURL(null, htmlData, "text/html", "utf-8", null)

        specRecyclerView.run {
            layoutManager = LinearLayoutManager(this@GoodsDetailActivity)
            var productSpecList = goodsDetailBean?.productSpecList

            adapter = MyAdapter(this@GoodsDetailActivity, productSpecList!!)
        }


        var ids = StringBuffer()
        for (index in goodsDetailBean.productSpecList.indices) {
            var proList = goodsDetailBean.productSpecList[index].proList
            for (ind in proList.indices) {

                if (index != 0) ids.append(",")
                ids.append(proList[0].specproid)
                break

            }
        }
        productSpecIds = ids.toString()
        Log.i("productSpecIds", "---------$productSpecIds")
        presenter.priceFromSpecId()

        productReviewRecyclerView.run {

            layoutManager = LinearLayoutManager(this@GoodsDetailActivity)
            adapter = ReviewAdapter(this@GoodsDetailActivity, commentlist!!)
        }
        var videourl = goodsDetailBeans?.product?.videourl
        Log.i("ssssssssss", "--------$videourl")
        if (videourl != "" && videourl != null)
            pVideoIv.visibility = VISIBLE
        initBanner(split!!)

        var commentNum = "";
        if (commentlist != null && commentlist.size > 0) {
            commentNum = "查看更多评价(" + commentlist.size + ")"
        } else {
            commentNum = "查看更多评价(0)"
        }
        productReview1.setText(commentNum)

    }


    inner class ReviewAdapter(
        var context: Context,
        var data: MutableList<GoodsDetailBean.CommentlistBean>
    ) :
        RecyclerView.Adapter<ReviewAdapter.ReviewHolder>() {
        var layoutInflater: LayoutInflater

        init {
            layoutInflater = LayoutInflater.from(context)
        }

        inner class ReviewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
            val avatarIv = itemView.findViewById<ImageView>(R.id.avatarIv)
            val nameTv = itemView.findViewById<TextView>(R.id.nameTv)
            val dateTv = itemView.findViewById<TextView>(R.id.dateTv)
            val levelTv = itemView.findViewById<TextView>(R.id.levelTv)
            val commentsTv = itemView.findViewById<TextView>(R.id.commentsTv)
            val commentsRecyclerView =
                itemView.findViewById<RecyclerView>(R.id.commentsRecyclerView)
        }

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ReviewHolder {
            var inflate = layoutInflater.inflate(R.layout.product_review_item_layout, parent, false)
            return ReviewHolder(inflate)
        }

        override fun getItemCount(): Int = when (data) {
            null -> 0
            else ->
                data.size
        }

        override fun onBindViewHolder(holder: ReviewHolder, position: Int) {
            with(data[position]) {
                holder.levelTv.text = levelname
                holder.dateTv.text = createtime
                holder.commentsTv.text = evaluate_ramrk
            }
            var imgurl = data[position].evimgurl
            var imgList = mutableListOf<String>()
            if (imgurl != null) {
                if (imgurl.contains(",")) {
                    var split = imgurl.split(",")
                    for (index in split.indices) {
                        imgList.add(split[index])
                    }
                } else {
                    imgList.add(imgurl)
                }
            }
//            var tel = data[position].tel
            holder.nameTv.text = data[position].tel
            holder.commentsRecyclerView.run {
                layoutManager = GridLayoutManager(context, 3)
                adapter = AdapterManager.getImageAdapter(this@GoodsDetailActivity, imgList)
            }

        }
    }


    inner class MyAdapter(
        var context: Context,
        var data: MutableList<GoodsDetailBean.ProductSpecListBean>
    ) : RecyclerView.Adapter<MyAdapter.MyHolder>() {
        var layoutInflater: LayoutInflater

        init {
            layoutInflater = LayoutInflater.from(context)
        }

        inner class MyHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
            val recyclerView = itemView.findViewById<RecyclerView>(R.id.specRecyclerView)
            val specNameTv = itemView.findViewById<TextView>(R.id.specNameTv)
        }

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyHolder {
            var view = layoutInflater.inflate(R.layout.spec_item_layout, null)
            return MyHolder(view)
        }

        override fun getItemCount(): Int = when (data) {
            null -> 0
            else -> data.size
        }

        override fun onBindViewHolder(holder: MyHolder, position: Int) {
            holder.specNameTv.text = data[position].specName
            var proList = data[position].proList
            proList[0].isSelect = true
            holder.recyclerView.run {
                layoutManager = FlowLayoutManager(context, true)
                adapter = MyChildAdapter(this@GoodsDetailActivity, proList)
            }
        }

    }


    inner class MyChildAdapter(
        var context: Context,
        var data: MutableList<GoodsDetailBean.ProductSpecListBean.ProListBean>
    ) :
        RecyclerView.Adapter<MyChildAdapter.MyChildHolder>() {
        var layoutInflater: LayoutInflater


        init {
            layoutInflater = LayoutInflater.from(context)
        }

        inner class MyChildHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
            val tv = itemView.findViewById<TextView>(R.id.tv)
        }

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyChildHolder {
            var inflate = layoutInflater.inflate(R.layout.flow_tv_item_layout, null)
            return MyChildHolder(inflate)
        }

        override fun getItemCount(): Int = when (data) {
            null -> 0
            else -> data.size
        }


        override fun onBindViewHolder(holder: MyChildHolder, position: Int) {
            holder.tv.text = data[position].specProName
            holder.tv.isSelected = data[position].isSelect
            holder.tv.setOnClickListener {
                for (index in data.indices) {
                    data[index].isSelect = index == position
                }
                notifyDataSetChanged()

                var ids = StringBuffer()
                for (index in goodsDetailBean.productSpecList.indices) {
                    var proList = goodsDetailBean.productSpecList[index].proList
                    for (ind in proList.indices) {
                        if (proList[ind].isSelect) {
                            if (index != 0) ids.append(",")
                            ids.append(proList[ind].specproid)
                        }
                    }
                }
                productSpecIds = ids.toString()
                Log.i("productSpecIds", "============$productSpecIds")
                showProgress()
                presenter.priceFromSpecId()

            }
        }
    }

    private fun getHtmlData(bodyHTML: String): String? {
        val head = ("<head>"
                + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> "
                + "<style>img{max-width: 100%; width:100%; height:auto;}*{margin:0px;}</style>"
                + "</head>")
        return "<html>$head<body>$bodyHTML</body></html>"
    }


    private fun initBanner(dataList: List<String>) {


        banner.addPageChangeListener(object : OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                var videourl = goodsDetailBean?.product?.videourl
                Log.i("position", "------$position------$videourl")
                if (position == 0) {
                    if (videourl != "" && videourl != null)
                        pVideoIv.visibility = VISIBLE
                } else {
                    pVideoIv.visibility = GONE
                }

            }

            override fun onPageScrollStateChanged(state: Int) {}
        })
        banner.setBannerPageClickListener(BannerPageClickListener { view, position ->

        })
        dataList.let {
            banner.setPages(dataList as List<Nothing>, MZHolderCreator { BannerViewHolder() })
        }
        banner.start()

    }


    override fun getGoodsDetailFailure(msg: String?) {
        hideProgress()
        toast(msg)
    }


    override fun getSpecIds(): String {
        return productSpecIds
    }

    override fun getShareInfoSuccess(shareInfoBean: GoodDetailShareBean?) {
        hideProgress()
        shareView.findViewById<ImageView>(R.id.iv_dismiss).setOnClickListener {
            shareDialog.dismiss()
        }
        shareView.findViewById<TextView>(R.id.sharePosterTv).setOnClickListener {
            shareDialog.dismiss()
            //分享海报
            var intent = Intent(this, PersonShare2Activity::class.java)
            intent.putExtra("cId", goodsDetailBean?.commodityid)
            startActivity(intent)
        }
        shareView.findViewById<TextView>(R.id.shareLinkTv).setOnClickListener {
            shareDialog.dismiss()
            //分享链接
            //初始化一个WXWebpageObject，填写url
            var webpage = WXWebpageObject();
            webpage.webpageUrl = shareInfoBean?.sharecomurl

            //用 WXWebpageObject 对象初始化一个 WXMediaMessage 对象
            var msg = WXMediaMessage(webpage)
            msg.title = getString(R.string.app_name)//商品名称
            msg.description = "快来下载吧！更多好礼等着你";//combz
            var thumbBmp = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
//            msg.thumbData = Util.bmpToByteArray(thumbBmp, true);

            //构造一个Req
            var req = SendMessageToWX.Req();
            req.transaction = System.currentTimeMillis().toString()
            req.message = msg;
//            req.scene = mTargetScene;
//            req.userOpenId = getOpenId();
            req.scene = SendMessageToWX.Req.WXSceneSession;//分享到微信好友
            //调用api接口，发送数据到微信
            MyApp.getWxApi().sendReq(req);
        }
        shareDialog.show()
    }


    override fun getShareInfoFailure(msg: String?) {
        hideProgress()
        toast(msg)

    }

    override fun getSpecIdSuccess(productSpecPriceBean: ProductSpecPriceBean?) {
        hideProgress()

        commodityspecid = productSpecPriceBean?.commodityspec?.commodityspecid!!
        if (productSpecPriceBean?.ifhui == "1") {
            specBVPrice.text = productSpecPriceBean?.commodityspec?.hybvprice.toString() + "BV"
            specPrice.text = "￥" + productSpecPriceBean?.commodityspec.hyprice.toString()
        } else {
            specBVPrice.text = productSpecPriceBean?.commodityspec?.bvprice.toString() + "BV"
            specPrice.text = "￥" + productSpecPriceBean?.commodityspec.price.toString()
        }

        specInStockTv.text = "库存" + productSpecPriceBean.commodityspec.stock
        Log.i("commodityspecid", "---------=====$commodityspecid")
    }

    override fun shareGetScoreSuccess() {//分享商品成功后，获取积分成功的回调
        hideProgress()
    }

    override fun shareGetScoreFailure(msg: String?) {
        hideProgress()
        toast(msg)
    }


    override fun onPause() {
        super.onPause()
        banner.pause()
    }

    override fun onDestroy() {
        super.onDestroy()
        presenter.detach()  //在onDestroy()生命周期中取消所有子线程里面的网络连接。
        myWebView.removeAllViews()
        if (myWebView != null) {
            myWebView.clearHistory()
            myWebView.clearCache(true)
        }
    }

    override fun cancelCollectionSuccess() {
        hideProgress()
        isCollection = "2"
        collectIv.setImageResource(R.mipmap.no_collect_iv)
    }

    override fun cancelCollectionFailure(msg: String?) {
        hideProgress()
        toast(msg)
    }

    override fun collectionSuccess() {
        hideProgress()
        isCollection = "1"
        collectIv.setImageResource(R.mipmap.yes_collect_iv)
    }

    override fun getProductNum(): String = specNumEt.text.toString()

    override fun getCommoditySpecId(): String = commodityspecid

    override fun collectionFailure(msg: String?) {
        hideProgress()
        toast(msg)
    }

    override fun addShopCarSuccess() {
        specDailog.dismiss()
        hideProgress()
    }

    override fun addShopCarFailure(msg: String?) {
        hideProgress()
        toast(msg)
    }

    override fun getCommodityId(): String {
        var commodityId = intent.extras?.getString("commodityId")
        return commodityId!!
    }
}
